package com.ph.demo.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by peng on 2019/4/15.
 */
public class FixedThreadPool implements Runnable{
    ReentrantLock lock = new ReentrantLock();

    public static FixedThreadPool pool = new FixedThreadPool();

    @Override
    public void run() {
        try {
            lock.lock();
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i <10 ; i++) {
            executorService.submit(pool);
            Thread.sleep(2000);

        }
        executorService.shutdown();
    }
}
